<template>
  <el-card shadow="never" class="mb20">
    <div class="table-page-search-wrapper">
      <el-form :model="form" ref="form" :inline="true" label-width="80px">
        <el-row :gutter="16">
          <el-col :span="6">
            <el-form-item>
              <el-date-picker
                style="width: 100%"
                v-model="date"
                type="daterange"
                range-separator="-"
                value-format="yyyy-MM-dd"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="3">
            <el-form-item>
              <el-select clearable v-model="form.feeState">
                <el-option label="全部" :value="0" />
                <el-option label="已收费" :value="1" />
                <el-option label="未收费" :value="2" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="3">
            <el-form-item prop="patientName">
              <el-input v-model="form.patientName" placeholder="患者姓名" />
            </el-form-item>
          </el-col>
          <el-col :span="3">
            <el-form-item prop="billHisDoctor">
              <el-input v-model="form.billHisDoctor" placeholder="开单医生" />
            </el-form-item>
          </el-col>
          <el-col :span="3">
            <el-form-item prop="chkHisDoctor">
              <el-input v-model="form.chkHisDoctor" placeholder="检查医生" />
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item>
              <el-tooltip class="item" effect="dark" content="查询" placement="top">
                <el-button icon="el-icon-search" type="primary" @click="handleSearch" />
              </el-tooltip>
              <el-tooltip class="item" effect="dark" content="重置" placement="top">
                <el-button icon="el-icon-refresh-right" @click="handleReset" />
              </el-tooltip>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
  </el-card>
</template>

<script>
import { boolTransNum, getPreMonth } from '@/utils/util'
export default {
  data() {
    return {
      date: null,
      detailRow: this.$route.params.detailRow,
      reportType: this.$route.params.type,
      form: {
        dateState: false,
        feeState: null
      }
    }
  },
  computed: {
    getRow() {
      return this.$route.params.detailRow
    },
    getType(n, o) {
      return this.$route.params.type
    }
  },
  watch: {
    getType(n, o) {
      console.log('n', n)
      if (n !== undefined && n !== o) {
        console.log('type watch', n)
        if (n === 'total') {
          this.form.feeState = 0
        } else if (n === 'have') {
          this.form.feeState = 1
        } else {
          this.form.feeState = 2
        }
        this.common()
      }
    },
    getRow: {
      handler(n, o) {
        if (n !== o && n !== undefined) {
          console.log('row watch', n)
          this.detailRow = Object.assign({}, n)
          this.common()
        }
      },
      deep: true
    }
  },
  created() {
    if (JSON.stringify(this.reportType) !== '{}') {
      // setSession('reportType', this.reportType)
      if (this.reportType === 'total') {
        this.form.feeState = 0
      } else if (this.reportType === 'have') {
        this.form.feeState = 1
      } else {
        this.form.feeState = 2
      }
    }
    this.common()
  },
  methods: {
    common() {
      console.log('detailRow', this.detailRow)
      if (this.detailRow.dt) {
        this.date = [this.detailRow.dt, this.detailRow.dt]
      } else {
        this.date = [this.detailRow.startTime, this.detailRow.endTime]
      }
      this.handleSearch()
    },
    handleSearch() {
      if (this.date) {
        this.$set(this.form, 'startTime', this.date[0])
        this.$set(this.form, 'endTime', this.date[1])
      } else {
        this.$set(this.form, 'startTime', null)
        this.$set(this.form, 'endTime', null)
      }
      const form = boolTransNum(this.form)

      console.log('form', form)
      this.$emit('search', form)
    },
    handleReset() {
      this.$refs.form.resetFields()
      this.handleSearch()
    }
  }
}
</script>
